//
//  Player.h
//  CLUB_my_part
//
//  Created by Константин Денисов on 8/19/13.
//  Copyright (c) 2013 Константин Денисов. All rights reserved.
//

#ifndef CLUB_my_part_Player_h
#define CLUB_my_part_Player_h


#include <iostream>
#include <string.h>
#include <vector>


#define PPlayer Player*


using namespace std;


const int Name_Random_Number = 6;

const int Number_Of_Classes = 4;


////////////////////////////////////////////////////////////////////////////////////////////////////////
//Classes - begin


enum Classes
{
    Warrior,
    Druid,
    Necromancer,
    Storm_Sorcerer
};


enum Plaing_Types
{
    Victim,
    Hunter
};


class Player
{
public:
    string username;
    Classes player_class;
    double rating;
    Plaing_Types now_type;
    
    //hunters and victims comes from first-met to the last-met
    vector< string > victims;
    vector< string > hunters;
    
    //i belive, you would not create Players with the same usernames !
    Player(string Name, Classes Class, double Rating, Plaing_Types Now_type,
           vector< string > Victims, vector< string > Hunters);
    
    Player(vector < PPlayer > Exist_Players);
    
    //from file ^^
    Player();
    
    void Print();
};


//Classes - end
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Some another functions - begin


//if there is no such name it will be NULL
PPlayer Find_Player_With_Name(string Name, vector < PPlayer > Players)
{
    vector< PPlayer >::iterator i;
    PPlayer result = NULL;
    
    for (i = Players.begin(); i != Players.end(); ++i)
        if ((*i)->username == Name)
        {
            result = *i;
            break;
        }
    
    return result;
}


bool Max_Rating(PPlayer a, PPlayer b)
{
    return (a->rating > b->rating);
}


//Some another functions - end
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//all Player functions - begin


Player::Player(string Name, Classes Class, double Rating, Plaing_Types Now_type,
               vector< string > Victims, vector< string > Hunters)
{
    username = Name;
    player_class = Class;
    victims = Victims;
    hunters = Hunters;
    rating = Rating;
    now_type = Now_type;
}


Player::Player(vector < PPlayer > Exist_Players)
{
    srand((int)time(NULL));
    //Вроде, что бы каждый раз рандомило.
    
    do
    {
        username.clear();
        
        for (int i = 0; i < Name_Random_Number; ++i)
            username.push_back((char)(rand() % 26 + (int)'a'));
    }
    while (Find_Player_With_Name(username, Exist_Players) != NULL);
    
    switch (rand() % Number_Of_Classes)
    {
        case 0:
            player_class = Warrior;
            break;
            
        case 1:
            player_class = Druid;
            break;
            
        case 2:
            player_class = Necromancer;
            break;
            
        case 3:
            player_class = Storm_Sorcerer;
            break;
            
        default:
            player_class = Warrior;
            break;
    }
    
    rating = 0.0;
    
    switch (rand() % 2)
    {
        case 0:
            now_type = Victim;
            break;
            
        case 1:
            now_type = Hunter;
            break;
            
        default:
            now_type = Victim;
            break;
    }
}


void Player::Print()
{
    cout <<username<<" ";
    
    switch (player_class)
    {
        case Warrior:
            cout <<"W ";
            break;
            
        case Druid:
            cout <<"D ";
            break;
            
        case Necromancer:
            cout <<"N ";
            break;
            
        case Storm_Sorcerer:
            cout <<"S ";
            break;
            
        default:
            cout <<"W ";
            break;
    }
    
    switch (now_type)
    {
        case Victim:
            cout <<"V\n";
            break;
            
        case Hunter:
            cout <<"H\n";
            break;
            
        default:
            cout <<"V\n";
            break;
    }
    
    cout <<rating<<"\n";
    
    cout <<victims.size()<<"\n";
    for (int i = 0; i < victims.size(); ++i)
        cout <<victims[i]<<" ";
    
    if (victims.size() > 0)
        cout <<"\n";
    
    cout <<hunters.size()<<"\n";
    for (int i = 0; i < hunters.size(); ++i)
        cout <<hunters[i]<<" ";
    
    if (hunters.size() > 0)
        cout <<"\n";
}


Player::Player()
{
    cin >>username;
    
    char c;
    
    cin >>c;
    switch (c)
    {
        case 'W':
            player_class = Warrior;
            break;
            
        case 'D':
            player_class = Druid;
            break;
            
        case 'N':
            player_class = Necromancer;
            break;
            
        case 'S':
            player_class = Storm_Sorcerer;
            break;
            
        default:
            player_class = Warrior;
            break;
    }
    
    cin >>c;
    switch (c)
    {
        case 'V':
            now_type = Victim;
            break;
            
        case 'H':
            now_type = Hunter;
            break;
            
        default:
            now_type = Victim;
            break;
    }
    
    cin >>rating;
    
    int n;
    string s;
    
    cin >>n;
    for (int i = 0; i < n; ++i)
    {
        cin >>s;
        victims.push_back(s);
    }
    
    cin >>n;
    for (int i = 0; i < n; ++i)
    {
        cin >>s;
        hunters.push_back(s);
    }
}


//all Player functions - end


#endif
